﻿using System.Collections.Generic;
using System.Linq;
using Registration;
using Registration.Localization.Formatting;

namespace License
{
    public partial class DriversLicense
    {
        
        public Driver Person
        {
            get { return (Driver)DataContext; }

            set
            {
                DataContext = value;
            }
        }

        public DriversLicense()
        {
            Initialize();
        }

        private void Initialize()
        {
            Driver.NameFormatter = new ProperNameFormatter();
            InitializeComponent();
        }

        public DriversLicense(Driver p)
        {
            Person = p;
            Initialize();
        }

        
        public void Load(string firstName, string surname)
        {
            using (var database = new Database())
            {
                Person = (from p in (IEnumerable<Driver>) database.Drivers
                          where p.FirstName == firstName && p.Surname == surname
                          select p).Single();
               
            }

        }
    }
}
